"""
研究一些类的特性
"""

class Student():
    name = None
    age = 18

    def say(self):
        self.name = "zhangsan"
        self.age = 20

print(Student.name)
print(Student.age)
print(id(Student.name))
print(id(Student.age))
print("**********************")

stu = Student()
print(stu.name)
print(stu.age)
print(id(stu.name))
print(id(stu.age))

print("**********************")
stu.name = "lisi"
stu.age = 25
print(stu.name)
print(stu.age)
print(id(stu.name))
print(id(stu.age))

class A():
    name = "AAA"
    age  =18
print(A.__dict__)
a = A()
print(a.__dict__)
a.age = 25
a.name = "BBB"
print(a.__dict__)

class Teacher():
    name = "cheny"
    age = 28

    def say(self):
        print("我叫{0}, 我今年{1}岁了".format(self.name, self.age))

    @staticmethod
    def sayAgain():
        print(__class__.name)
        print(__class__.age)
        print("nice to meet you")

t = Teacher()
t.say()
t.sayAgain()

#鸭子模型
class A():
    name = "zhangsan"
    age = 20

    def __init__(self):
        self.name = "aaaa"
        self.age = 18

    def say(self):
        print("My name is {0}, and I am {1} years old".format(self.name, self.age))

class B():
    name = "lisi"
    age = 80

a = A()
a.say()  #此时运行不会有任何问题，输出 aaa 和 18
#A.say()  #此时会报错，原因是say方法中应该有一个slef参数，但调用的时候没有传入
A.say(A)    #此时可以运行，但输出的结果是类的name和age，即 zhangsan 和 20
A.say(B)    #此时调用并不会报错，原因是B中也有name和age属性，会输出B的name和age，即 lisi 和 80，这就是鸭子模型
